<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>1-4</title>
    <style type="text/css">
        body{
            width: 100%;
            height: 100%;
        }
        #dd{
            margin-left: 500px;
        }
        .bb{
            margin-top: 300px;
            margin-left: 620px;
        }
        #dd>div{
            height: 100px;
            width: 100px;
            margin: 10px 10px;
            background-color: #000000;
            display: inline-block;
        }
        button{
            margin: 10px auto;
        }
    </style>
</head>
<body>
<button type="button" onclick="f()" class="bb">点击将DIV变为红色</button>
<div id="dd">
    <div id="1"></div>
    <div id="2"></div>
    <div id="3"></div>
</div>

<script type="text/javascript">
    var arr=document.getElementById('dd').getElementsByTagName('div');
    function f(){
        let i=0;
        for(i;i<arr.length;i++){
            arr[i].style.backgroundColor='red';
        }
    }
</script>
</body>
</html>